import { BasicColumn, FormSchema } from '@/components/Table';
import { formatToDateTime } from '@/utils/dateUtil';

import { h } from 'vue';
import { Tag } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    title: '岗位编号',
    dataIndex: 'id',
    // width: 180,
  },
  {
    title: '岗位编码',
    dataIndex: 'postCode',
    // width: 180,
  },
  {
    title: '岗位名称',
    dataIndex: 'postName',
    // width: 180,
  },
  {
    title: '岗位排序',
    dataIndex: 'postSort',
    // width: 180,
  },
  {
    title: '状态',
    dataIndex: 'postStatus',
    customRender: ({ record }) => {
      const status = record.postStatus;
      const enable = status === '0' ? true : false;
      const color = enable ? 'green' : 'red';
      const text = enable ? '正常' : '禁用';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
    customRender: ({ text }) => formatToDateTime(text),
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'postName',
    label: '岗位名称',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'postStatus',
    label: '岗位状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '正常', value: '0' },
        { label: '禁用', value: '1' },
      ],
    },
    colProps: { span: 4 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'postName',
    label: '岗位名称',
    component: 'Input',
    required: true,
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
    rules: [{ min: 2, max: 50, message: '岗位名称长度必须介于 2 和 50 之间', trigger: 'blur' }],
  },
  {
    field: 'postCode',
    label: '岗位编码',
    required: true,
    component: 'Input',
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
    rules: [{ min: 5, max: 50, message: '岗位编码长度必须介于 5 和 50 之间', trigger: 'blur' }],
  },
  {
    field: 'postSort',
    label: '岗位顺序',
    component: 'InputNumber',
    defaultValue: 0,
    componentProps: {
      min: 0,
      precision: 0,
    },
    required: true,
  },
  {
    field: 'postStatus',
    label: '岗位状态',
    component: 'RadioGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '正常', value: '0' },
        { label: '禁用', value: '1' },
      ],
    },
  },
];
